{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": 61,
      "metadata": {
        "id": "mS0bWISTqhMI"
      },
      "outputs": [],
      "source": [
        "import dgl.nn as dglnn\n",
        "from dgl import from_networkx\n",
        "import torch.nn as nn\n",
        "import torch as th\n",
        "import torch.nn.functional as F\n",
        "import dgl.function as fn\n",
        "import networkx as nx\n",
        "import pandas as pd\n",
        "import socket\n",
        "import struct\n",
        "import random\n",
        "from sklearn.preprocessing import LabelEncoder\n",
        "from sklearn.preprocessing import StandardScaler\n",
        "from sklearn.model_selection import train_test_split\n",
        "import category_encoders as ce\n",
        "from sklearn.decomposition import PCA\n",
        "import seaborn as sns\n",
        "import matplotlib.pyplot as plt\n",
        "import numpy as np\n",
        "from sklearn import metrics"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 2,
      "metadata": {
        "id": "ki0watiErdJp"
      },
      "outputs": [],
      "source": [
        "data = pd.read_csv('NF-ToN-IoT.csv')"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 3,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 416
        },
        "id": "0JmyVopVrqWQ",
        "outputId": "25564cc3-8e02-4f28-8485-b2068961f285"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>IPV4_SRC_ADDR</th>\n",
              "      <th>L4_SRC_PORT</th>\n",
              "      <th>IPV4_DST_ADDR</th>\n",
              "      <th>L4_DST_PORT</th>\n",
              "      <th>PROTOCOL</th>\n",
              "      <th>L7_PROTO</th>\n",
              "      <th>IN_BYTES</th>\n",
              "      <th>OUT_BYTES</th>\n",
              "      <th>IN_PKTS</th>\n",
              "      <th>OUT_PKTS</th>\n",
              "      <th>TCP_FLAGS</th>\n",
              "      <th>FLOW_DURATION_MILLISECONDS</th>\n",
              "      <th>Label</th>\n",
              "      <th>Attack</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>192.168.1.195</td>\n",
              "      <td>63318</td>\n",
              "      <td>52.139.250.253</td>\n",
              "      <td>443</td>\n",
              "      <td>6</td>\n",
              "      <td>91.00</td>\n",
              "      <td>181</td>\n",
              "      <td>165</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>24</td>\n",
              "      <td>327</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>192.168.1.79</td>\n",
              "      <td>57442</td>\n",
              "      <td>192.168.1.255</td>\n",
              "      <td>15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>192.168.1.79</td>\n",
              "      <td>57452</td>\n",
              "      <td>239.255.255.250</td>\n",
              "      <td>15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>192.168.1.193</td>\n",
              "      <td>138</td>\n",
              "      <td>192.168.1.255</td>\n",
              "      <td>138</td>\n",
              "      <td>17</td>\n",
              "      <td>10.16</td>\n",
              "      <td>472</td>\n",
              "      <td>0</td>\n",
              "      <td>2</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>192.168.1.79</td>\n",
              "      <td>51989</td>\n",
              "      <td>192.168.1.255</td>\n",
              "      <td>15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379269</th>\n",
              "      <td>192.168.1.31</td>\n",
              "      <td>58032</td>\n",
              "      <td>192.168.1.194</td>\n",
              "      <td>80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9433</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379270</th>\n",
              "      <td>192.168.1.31</td>\n",
              "      <td>58034</td>\n",
              "      <td>192.168.1.194</td>\n",
              "      <td>80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9221</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379271</th>\n",
              "      <td>192.168.1.31</td>\n",
              "      <td>58036</td>\n",
              "      <td>192.168.1.194</td>\n",
              "      <td>80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9656</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379272</th>\n",
              "      <td>192.168.1.31</td>\n",
              "      <td>58038</td>\n",
              "      <td>192.168.1.194</td>\n",
              "      <td>80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>10046</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379273</th>\n",
              "      <td>192.168.1.31</td>\n",
              "      <td>58040</td>\n",
              "      <td>192.168.1.194</td>\n",
              "      <td>80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>10485</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>1379274 rows × 14 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "         IPV4_SRC_ADDR  L4_SRC_PORT  ... Label  Attack\n",
              "0        192.168.1.195        63318  ...     0  Benign\n",
              "1         192.168.1.79        57442  ...     0  Benign\n",
              "2         192.168.1.79        57452  ...     0  Benign\n",
              "3        192.168.1.193          138  ...     0  Benign\n",
              "4         192.168.1.79        51989  ...     0  Benign\n",
              "...                ...          ...  ...   ...     ...\n",
              "1379269   192.168.1.31        58032  ...     1    ddos\n",
              "1379270   192.168.1.31        58034  ...     1    ddos\n",
              "1379271   192.168.1.31        58036  ...     1    ddos\n",
              "1379272   192.168.1.31        58038  ...     1    ddos\n",
              "1379273   192.168.1.31        58040  ...     1    ddos\n",
              "\n",
              "[1379274 rows x 14 columns]"
            ]
          },
          "execution_count": 3,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 4,
      "metadata": {
        "id": "PoVYaeFZtJBd"
      },
      "outputs": [],
      "source": [
        "data['IPV4_SRC_ADDR'] = data.IPV4_SRC_ADDR.apply(lambda x: socket.inet_ntoa(struct.pack('>I', random.randint(0xac100001, 0xac1f0001))))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 5,
      "metadata": {
        "id": "zs4z58WCtu8k"
      },
      "outputs": [],
      "source": [
        "data['IPV4_SRC_ADDR'] = data.IPV4_SRC_ADDR.apply(str)\n",
        "data['L4_SRC_PORT'] = data.L4_SRC_PORT.apply(str)\n",
        "data['IPV4_DST_ADDR'] = data.IPV4_DST_ADDR.apply(str)\n",
        "data['L4_DST_PORT'] = data.L4_DST_PORT.apply(str)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 6,
      "metadata": {
        "id": "9EEwTAK3tle9"
      },
      "outputs": [],
      "source": [
        "data['IPV4_SRC_ADDR'] = data['IPV4_SRC_ADDR'] + ':' + data['L4_SRC_PORT']\n",
        "data['IPV4_DST_ADDR'] = data['IPV4_DST_ADDR'] + ':' + data['L4_DST_PORT']"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 7,
      "metadata": {
        "id": "xbdaHUxOtzd-"
      },
      "outputs": [],
      "source": [
        "data.drop(columns=['L4_SRC_PORT','L4_DST_PORT'],inplace=True)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 8,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 416
        },
        "id": "CN9rLLmr0eeI",
        "outputId": "a58631d9-2eb4-4afb-b878-bd9977a7b773"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>IPV4_SRC_ADDR</th>\n",
              "      <th>IPV4_DST_ADDR</th>\n",
              "      <th>PROTOCOL</th>\n",
              "      <th>L7_PROTO</th>\n",
              "      <th>IN_BYTES</th>\n",
              "      <th>OUT_BYTES</th>\n",
              "      <th>IN_PKTS</th>\n",
              "      <th>OUT_PKTS</th>\n",
              "      <th>TCP_FLAGS</th>\n",
              "      <th>FLOW_DURATION_MILLISECONDS</th>\n",
              "      <th>Label</th>\n",
              "      <th>Attack</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>172.21.71.96:63318</td>\n",
              "      <td>52.139.250.253:443</td>\n",
              "      <td>6</td>\n",
              "      <td>91.00</td>\n",
              "      <td>181</td>\n",
              "      <td>165</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>24</td>\n",
              "      <td>327</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>172.20.204.65:57442</td>\n",
              "      <td>192.168.1.255:15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>172.22.97.207:57452</td>\n",
              "      <td>239.255.255.250:15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>172.17.112.113:138</td>\n",
              "      <td>192.168.1.255:138</td>\n",
              "      <td>17</td>\n",
              "      <td>10.16</td>\n",
              "      <td>472</td>\n",
              "      <td>0</td>\n",
              "      <td>2</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>172.16.58.135:51989</td>\n",
              "      <td>192.168.1.255:15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>Benign</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379269</th>\n",
              "      <td>172.18.152.95:58032</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9433</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379270</th>\n",
              "      <td>172.29.52.96:58034</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9221</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379271</th>\n",
              "      <td>172.27.238.17:58036</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9656</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379272</th>\n",
              "      <td>172.28.160.92:58038</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>10046</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379273</th>\n",
              "      <td>172.26.25.45:58040</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>10485</td>\n",
              "      <td>1</td>\n",
              "      <td>ddos</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>1379274 rows × 12 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "               IPV4_SRC_ADDR          IPV4_DST_ADDR  ...  Label  Attack\n",
              "0         172.21.71.96:63318     52.139.250.253:443  ...      0  Benign\n",
              "1        172.20.204.65:57442    192.168.1.255:15600  ...      0  Benign\n",
              "2        172.22.97.207:57452  239.255.255.250:15600  ...      0  Benign\n",
              "3         172.17.112.113:138      192.168.1.255:138  ...      0  Benign\n",
              "4        172.16.58.135:51989    192.168.1.255:15600  ...      0  Benign\n",
              "...                      ...                    ...  ...    ...     ...\n",
              "1379269  172.18.152.95:58032       192.168.1.194:80  ...      1    ddos\n",
              "1379270   172.29.52.96:58034       192.168.1.194:80  ...      1    ddos\n",
              "1379271  172.27.238.17:58036       192.168.1.194:80  ...      1    ddos\n",
              "1379272  172.28.160.92:58038       192.168.1.194:80  ...      1    ddos\n",
              "1379273   172.26.25.45:58040       192.168.1.194:80  ...      1    ddos\n",
              "\n",
              "[1379274 rows x 12 columns]"
            ]
          },
          "execution_count": 8,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 9,
      "metadata": {
        "id": "C_WU15ngvnBM"
      },
      "outputs": [],
      "source": [
        "data.drop(columns=['Attack'],inplace = True)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 10,
      "metadata": {
        "id": "Q0d3nbdiv37j"
      },
      "outputs": [],
      "source": [
        "data.rename(columns={\"Label\": \"label\"},inplace = True)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 11,
      "metadata": {
        "id": "SVgjPVfg03XG"
      },
      "outputs": [],
      "source": [
        "label = data.label"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 12,
      "metadata": {
        "id": "ADl2Fj7H08Rr"
      },
      "outputs": [],
      "source": [
        "data.drop(columns=['label'],inplace = True)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 13,
      "metadata": {
        "id": "qhsZMD3uwLk7"
      },
      "outputs": [],
      "source": [
        "scaler = StandardScaler()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 14,
      "metadata": {
        "id": "aukoVdNf2zcp"
      },
      "outputs": [],
      "source": [
        "data =  pd.concat([data, label], axis=1)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 15,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 416
        },
        "id": "IP-ZEZW4nxSm",
        "outputId": "fa635f5a-f526-437b-9b91-59e737a73b1e"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>IPV4_SRC_ADDR</th>\n",
              "      <th>IPV4_DST_ADDR</th>\n",
              "      <th>PROTOCOL</th>\n",
              "      <th>L7_PROTO</th>\n",
              "      <th>IN_BYTES</th>\n",
              "      <th>OUT_BYTES</th>\n",
              "      <th>IN_PKTS</th>\n",
              "      <th>OUT_PKTS</th>\n",
              "      <th>TCP_FLAGS</th>\n",
              "      <th>FLOW_DURATION_MILLISECONDS</th>\n",
              "      <th>label</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>0</th>\n",
              "      <td>172.21.71.96:63318</td>\n",
              "      <td>52.139.250.253:443</td>\n",
              "      <td>6</td>\n",
              "      <td>91.00</td>\n",
              "      <td>181</td>\n",
              "      <td>165</td>\n",
              "      <td>2</td>\n",
              "      <td>1</td>\n",
              "      <td>24</td>\n",
              "      <td>327</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1</th>\n",
              "      <td>172.20.204.65:57442</td>\n",
              "      <td>192.168.1.255:15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>2</th>\n",
              "      <td>172.22.97.207:57452</td>\n",
              "      <td>239.255.255.250:15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>3</th>\n",
              "      <td>172.17.112.113:138</td>\n",
              "      <td>192.168.1.255:138</td>\n",
              "      <td>17</td>\n",
              "      <td>10.16</td>\n",
              "      <td>472</td>\n",
              "      <td>0</td>\n",
              "      <td>2</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>4</th>\n",
              "      <td>172.16.58.135:51989</td>\n",
              "      <td>192.168.1.255:15600</td>\n",
              "      <td>17</td>\n",
              "      <td>0.00</td>\n",
              "      <td>63</td>\n",
              "      <td>0</td>\n",
              "      <td>1</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379269</th>\n",
              "      <td>172.18.152.95:58032</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9433</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379270</th>\n",
              "      <td>172.29.52.96:58034</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9221</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379271</th>\n",
              "      <td>172.27.238.17:58036</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>9656</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379272</th>\n",
              "      <td>172.28.160.92:58038</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>10046</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1379273</th>\n",
              "      <td>172.26.25.45:58040</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>6</td>\n",
              "      <td>7.00</td>\n",
              "      <td>216</td>\n",
              "      <td>180</td>\n",
              "      <td>4</td>\n",
              "      <td>3</td>\n",
              "      <td>18</td>\n",
              "      <td>10485</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>1379274 rows × 11 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "               IPV4_SRC_ADDR  ... label\n",
              "0         172.21.71.96:63318  ...     0\n",
              "1        172.20.204.65:57442  ...     0\n",
              "2        172.22.97.207:57452  ...     0\n",
              "3         172.17.112.113:138  ...     0\n",
              "4        172.16.58.135:51989  ...     0\n",
              "...                      ...  ...   ...\n",
              "1379269  172.18.152.95:58032  ...     1\n",
              "1379270   172.29.52.96:58034  ...     1\n",
              "1379271  172.27.238.17:58036  ...     1\n",
              "1379272  172.28.160.92:58038  ...     1\n",
              "1379273   172.26.25.45:58040  ...     1\n",
              "\n",
              "[1379274 rows x 11 columns]"
            ]
          },
          "execution_count": 15,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "data"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 16,
      "metadata": {
        "id": "PUa4uJbewQc7"
      },
      "outputs": [],
      "source": [
        "X_train, X_test, y_train, y_test = train_test_split(\n",
        "     data, label, test_size=0.3, random_state=123,stratify= label)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 17,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "z3DrIWDHqNxp",
        "outputId": "4bdbd2d8-5ba9-41b7-defd-b42b8c44f061"
      },
      "outputs": [
        {
          "name": "stderr",
          "output_type": "stream",
          "text": [
            "/usr/local/lib/python3.6/dist-packages/category_encoders/utils.py:21: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead\n",
            "  elif pd.api.types.is_categorical(cols):\n"
          ]
        }
      ],
      "source": [
        "encoder = ce.TargetEncoder(cols=['TCP_FLAGS','L7_PROTO','PROTOCOL'])\n",
        "encoder.fit(X_train, y_train)\n",
        "X_train = encoder.transform(X_train)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 18,
      "metadata": {
        "id": "EDKYHCbcqN81"
      },
      "outputs": [],
      "source": [
        "cols_to_norm = list(set(list(X_train.iloc[:, 2:].columns ))  - set(list(['label'])) )\n",
        "X_train[cols_to_norm] = scaler.fit_transform(X_train[cols_to_norm])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 19,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 416
        },
        "id": "-TkDCimdrHXQ",
        "outputId": "f4ed6f4c-72b6-4b3e-b00b-912cec4b9bbf"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>IPV4_SRC_ADDR</th>\n",
              "      <th>IPV4_DST_ADDR</th>\n",
              "      <th>PROTOCOL</th>\n",
              "      <th>L7_PROTO</th>\n",
              "      <th>IN_BYTES</th>\n",
              "      <th>OUT_BYTES</th>\n",
              "      <th>IN_PKTS</th>\n",
              "      <th>OUT_PKTS</th>\n",
              "      <th>TCP_FLAGS</th>\n",
              "      <th>FLOW_DURATION_MILLISECONDS</th>\n",
              "      <th>label</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1136181</th>\n",
              "      <td>172.27.155.212:46172</td>\n",
              "      <td>192.168.1.194:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.007181</td>\n",
              "      <td>-0.025163</td>\n",
              "      <td>-0.004989</td>\n",
              "      <td>-0.008516</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>0.029279</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>618165</th>\n",
              "      <td>172.23.206.154:49662</td>\n",
              "      <td>192.168.1.195:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005863</td>\n",
              "      <td>-0.005514</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.005293</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.052318</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1049352</th>\n",
              "      <td>172.18.28.97:443</td>\n",
              "      <td>192.168.1.30:41844</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>-0.650380</td>\n",
              "      <td>-0.008074</td>\n",
              "      <td>-0.025817</td>\n",
              "      <td>-0.005957</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>-2.607223</td>\n",
              "      <td>-0.054776</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1138369</th>\n",
              "      <td>172.17.99.26:80</td>\n",
              "      <td>192.168.1.31:38866</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.008074</td>\n",
              "      <td>-0.025817</td>\n",
              "      <td>-0.005957</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>-2.607223</td>\n",
              "      <td>-0.055219</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>116060</th>\n",
              "      <td>172.20.162.111:40068</td>\n",
              "      <td>192.168.1.190:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005373</td>\n",
              "      <td>-0.004783</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.004218</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.054358</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>934717</th>\n",
              "      <td>172.18.236.87:47960</td>\n",
              "      <td>192.168.1.184:443</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>-0.650380</td>\n",
              "      <td>-0.007747</td>\n",
              "      <td>-0.025740</td>\n",
              "      <td>-0.005635</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>-0.055286</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>549787</th>\n",
              "      <td>172.23.5.99:55448</td>\n",
              "      <td>192.168.1.184:443</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>-0.650380</td>\n",
              "      <td>-0.002639</td>\n",
              "      <td>-0.005014</td>\n",
              "      <td>-0.003699</td>\n",
              "      <td>-0.002069</td>\n",
              "      <td>0.579017</td>\n",
              "      <td>-0.054300</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>566730</th>\n",
              "      <td>172.22.199.18:44906</td>\n",
              "      <td>52.59.177.21:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.745102</td>\n",
              "      <td>-0.005449</td>\n",
              "      <td>0.096934</td>\n",
              "      <td>-0.004344</td>\n",
              "      <td>0.002229</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.041907</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1240787</th>\n",
              "      <td>172.16.161.74:56578</td>\n",
              "      <td>192.168.1.184:443</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>-0.650380</td>\n",
              "      <td>-0.007747</td>\n",
              "      <td>-0.025740</td>\n",
              "      <td>-0.005635</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>-0.055286</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>454344</th>\n",
              "      <td>172.26.67.180:60330</td>\n",
              "      <td>192.168.1.195:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005318</td>\n",
              "      <td>-0.019623</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.006367</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.053137</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>965491 rows × 11 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "                IPV4_SRC_ADDR  ... label\n",
              "1136181  172.27.155.212:46172  ...     1\n",
              "618165   172.23.206.154:49662  ...     1\n",
              "1049352      172.18.28.97:443  ...     0\n",
              "1138369       172.17.99.26:80  ...     0\n",
              "116060   172.20.162.111:40068  ...     1\n",
              "...                       ...  ...   ...\n",
              "934717    172.18.236.87:47960  ...     1\n",
              "549787      172.23.5.99:55448  ...     1\n",
              "566730    172.22.199.18:44906  ...     1\n",
              "1240787   172.16.161.74:56578  ...     1\n",
              "454344    172.26.67.180:60330  ...     1\n",
              "\n",
              "[965491 rows x 11 columns]"
            ]
          },
          "execution_count": 19,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "X_train"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 20,
      "metadata": {
        "id": "ek535MkWwUHN"
      },
      "outputs": [],
      "source": [
        "X_train['h'] = X_train[ cols_to_norm ].values.tolist()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 21,
      "metadata": {
        "id": "OIrcNfMSwa0j"
      },
      "outputs": [],
      "source": [
        "G = nx.from_pandas_edgelist(X_train, \"IPV4_SRC_ADDR\", \"IPV4_DST_ADDR\", ['h','label'],create_using=nx.MultiGraph())"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 22,
      "metadata": {
        "id": "QluLSxbiwn7M"
      },
      "outputs": [],
      "source": [
        "G = G.to_directed()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 23,
      "metadata": {
        "id": "2zClkKEzwrVb"
      },
      "outputs": [],
      "source": [
        "G = from_networkx(G,edge_attrs=['h','label'] )\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 24,
      "metadata": {
        "id": "9jlBYgE8wsW7"
      },
      "outputs": [],
      "source": [
        "# Eq1\n",
        "G.ndata['h'] = th.ones(G.num_nodes(), G.edata['h'].shape[1])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 25,
      "metadata": {
        "id": "E7Vc6IELwuJr"
      },
      "outputs": [],
      "source": [
        "G.edata['train_mask'] = th.ones(len(G.edata['h']), dtype=th.bool)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 26,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "BIx7-W6s46Ju",
        "outputId": "7fc7842a-04d1-47b2-d82c-c408e6d6bc15"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "tensor([True, True, True,  ..., True, True, True])"
            ]
          },
          "execution_count": 26,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "G.edata['train_mask'] "
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 27,
      "metadata": {
        "id": "DzDap1MR5e95"
      },
      "outputs": [],
      "source": [
        "def compute_accuracy(pred, labels):\n",
        "    return (pred.argmax(1) == labels).float().mean().item()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 28,
      "metadata": {
        "id": "5VzTQxAR5HoT"
      },
      "outputs": [],
      "source": [
        "class SAGELayer(nn.Module):\n",
        "    def __init__(self, ndim_in, edims, ndim_out, activation):\n",
        "        super(SAGELayer, self).__init__()\n",
        "        ### force to outut fix dimensions\n",
        "        self.W_msg = nn.Linear(ndim_in + edims, ndim_out)\n",
        "        ### apply weight\n",
        "        self.W_apply = nn.Linear(ndim_in + ndim_out, ndim_out)\n",
        "        self.activation = activation\n",
        "\n",
        "    def message_func(self, edges):\n",
        "        return {'m': self.W_msg(th.cat([edges.src['h'], edges.data['h']], 2))}\n",
        "\n",
        "    def forward(self, g_dgl, nfeats, efeats):\n",
        "        with g_dgl.local_scope():\n",
        "            g = g_dgl\n",
        "            g.ndata['h'] = nfeats\n",
        "            g.edata['h'] = efeats\n",
        "            # Eq4\n",
        "            g.update_all(self.message_func, fn.mean('m', 'h_neigh'))\n",
        "            # Eq5          \n",
        "            g.ndata['h'] = F.relu(self.W_apply(th.cat([g.ndata['h'], g.ndata['h_neigh']], 2)))\n",
        "            return g.ndata['h']\n",
        "\n",
        "\n",
        "class SAGE(nn.Module):\n",
        "    def __init__(self, ndim_in, ndim_out, edim, activation, dropout):\n",
        "        super(SAGE, self).__init__()\n",
        "        self.layers = nn.ModuleList()\n",
        "        self.layers.append(SAGELayer(ndim_in, edim, 128, activation))\n",
        "        self.layers.append(SAGELayer(128, edim, ndim_out, activation))\n",
        "        self.dropout = nn.Dropout(p=dropout)\n",
        "\n",
        "    def forward(self, g, nfeats, efeats):\n",
        "        for i, layer in enumerate(self.layers):\n",
        "            if i != 0:\n",
        "                nfeats = self.dropout(nfeats)\n",
        "            nfeats = layer(g, nfeats, efeats)\n",
        "        return nfeats.sum(1)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 29,
      "metadata": {
        "id": "hrLYvze5wwMi"
      },
      "outputs": [],
      "source": [
        "class MLPPredictor(nn.Module):\n",
        "    def __init__(self, in_features, out_classes):\n",
        "        super().__init__()\n",
        "        self.W = nn.Linear(in_features * 2, out_classes)\n",
        "\n",
        "    def apply_edges(self, edges):\n",
        "        h_u = edges.src['h']\n",
        "        h_v = edges.dst['h']\n",
        "        score = self.W(th.cat([h_u, h_v], 1))\n",
        "        return {'score': score}\n",
        "\n",
        "    def forward(self, graph, h):\n",
        "        with graph.local_scope():\n",
        "            graph.ndata['h'] = h\n",
        "            graph.apply_edges(self.apply_edges)\n",
        "            return graph.edata['score']"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 30,
      "metadata": {
        "id": "GPLg-kCcwxLa"
      },
      "outputs": [],
      "source": [
        "G.ndata['h'] = th.reshape(G.ndata['h'], (G.ndata['h'].shape[0], 1,G.ndata['h'].shape[1]))\n",
        "G.edata['h'] = th.reshape(G.edata['h'], (G.edata['h'].shape[0], 1,G.edata['h'].shape[1]))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 31,
      "metadata": {
        "id": "SwdZs785w1dT"
      },
      "outputs": [],
      "source": [
        "class Model(nn.Module):\n",
        "    def __init__(self, ndim_in, ndim_out, edim, activation, dropout):\n",
        "        super().__init__()\n",
        "        self.gnn = SAGE(ndim_in, ndim_out, edim, activation, dropout)\n",
        "        self.pred = MLPPredictor(ndim_out, 2)\n",
        "    def forward(self, g, nfeats, efeats):\n",
        "        h = self.gnn(g, nfeats, efeats)\n",
        "        return self.pred(g, h)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 80,
      "metadata": {
        "id": "BEw7J1Z45R62"
      },
      "outputs": [],
      "source": [
        "from sklearn.utils import class_weight\n",
        "class_weights = class_weight.compute_class_weight('balanced',\n",
        "                                                 np.unique(G.edata['label'].cpu().numpy()),\n",
        "                                                 G.edata['label'].cpu().numpy())"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 81,
      "metadata": {
        "id": "IZ39m_ib5VFV"
      },
      "outputs": [],
      "source": [
        "class_weights = th.FloatTensor(class_weights).cuda()\n",
        "criterion = nn.CrossEntropyLoss(weight = class_weights)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 35,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "Rj3DHIZmw4IM",
        "outputId": "830ae02b-f35f-4f1e-a8b8-6ef1eb769de3"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "device(type='cuda', index=0)"
            ]
          },
          "execution_count": 35,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "G = G.to('cuda:0')\n",
        "G.device"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 36,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "qdlVG3JOw5Qj",
        "outputId": "f733c930-ea59-4944-ff5a-619a6a5c9ba1"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "device(type='cuda', index=0)"
            ]
          },
          "execution_count": 36,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "G.ndata['h'].device\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 37,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "dvt3pnXmw6U7",
        "outputId": "78e3a790-ba24-4820-d0d7-feced5330b45"
      },
      "outputs": [
        {
          "data": {
            "text/plain": [
              "device(type='cuda', index=0)"
            ]
          },
          "execution_count": 37,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "G.edata['h'].device\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 82,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "-_eTiHzWw8Cz",
        "outputId": "4333b4bf-cadf-4b58-f083-e052ccd984ec"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "Training acc: 0.9556666016578674\n",
            "Training acc: 0.956838071346283\n",
            "Training acc: 0.9754611849784851\n",
            "Training acc: 0.9739500880241394\n",
            "Training acc: 0.9744213223457336\n",
            "Training acc: 0.9794814586639404\n",
            "Training acc: 0.9844892621040344\n",
            "Training acc: 0.990038275718689\n",
            "Training acc: 0.9919476509094238\n",
            "Training acc: 0.9920507073402405\n",
            "Training acc: 0.9917658567428589\n",
            "Training acc: 0.9937198162078857\n",
            "Training acc: 0.99267578125\n",
            "Training acc: 0.9931594729423523\n",
            "Training acc: 0.9935457706451416\n",
            "Training acc: 0.9935540556907654\n",
            "Training acc: 0.9949637055397034\n",
            "Training acc: 0.9957457184791565\n",
            "Training acc: 0.995270848274231\n",
            "Training acc: 0.9950813055038452\n",
            "Training acc: 0.9958264827728271\n",
            "Training acc: 0.9953888654708862\n",
            "Training acc: 0.9946452379226685\n",
            "Training acc: 0.9957317113876343\n",
            "Training acc: 0.9963982105255127\n",
            "Training acc: 0.9951449632644653\n",
            "Training acc: 0.9963365793228149\n",
            "Training acc: 0.996349036693573\n",
            "Training acc: 0.9969777464866638\n",
            "Training acc: 0.9972475171089172\n",
            "Training acc: 0.9975199103355408\n",
            "Training acc: 0.9975830912590027\n",
            "Training acc: 0.9963350296020508\n",
            "Training acc: 0.9974676370620728\n",
            "Training acc: 0.997662365436554\n",
            "Training acc: 0.9961931705474854\n",
            "Training acc: 0.9970393776893616\n",
            "Training acc: 0.9976685643196106\n",
            "Training acc: 0.9967793822288513\n",
            "Training acc: 0.9975820779800415\n",
            "Training acc: 0.9978933334350586\n",
            "Training acc: 0.9976628422737122\n",
            "Training acc: 0.9979808330535889\n",
            "Training acc: 0.997951865196228\n",
            "Training acc: 0.9979958534240723\n",
            "Training acc: 0.9978244304656982\n",
            "Training acc: 0.9948290586471558\n",
            "Training acc: 0.9971858859062195\n",
            "Training acc: 0.9968363642692566\n",
            "Training acc: 0.9975281953811646\n",
            "Training acc: 0.9976934194564819\n",
            "Training acc: 0.9977110028266907\n",
            "Training acc: 0.9980968236923218\n",
            "Training acc: 0.9960212111473083\n",
            "Training acc: 0.9979860186576843\n",
            "Training acc: 0.9976799488067627\n",
            "Training acc: 0.9981263875961304\n",
            "Training acc: 0.9979901909828186\n",
            "Training acc: 0.9981895685195923\n",
            "Training acc: 0.9925452470779419\n",
            "Training acc: 0.9978213310241699\n",
            "Training acc: 0.9980983734130859\n",
            "Training acc: 0.9980020523071289\n",
            "Training acc: 0.9979461431503296\n",
            "Training acc: 0.9980584979057312\n",
            "Training acc: 0.9979891180992126\n",
            "Training acc: 0.9983428120613098\n",
            "Training acc: 0.9980403780937195\n",
            "Training acc: 0.9966923594474792\n",
            "Training acc: 0.9972744584083557\n",
            "Training acc: 0.9958270192146301\n",
            "Training acc: 0.9961610436439514\n",
            "Training acc: 0.9979124665260315\n",
            "Training acc: 0.9981890320777893\n",
            "Training acc: 0.9983526468276978\n",
            "Training acc: 0.9976059198379517\n",
            "Training acc: 0.998014509677887\n",
            "Training acc: 0.9954764246940613\n",
            "Training acc: 0.9981657266616821\n",
            "Training acc: 0.9983215928077698\n",
            "Training acc: 0.9914064407348633\n",
            "Training acc: 0.9976587295532227\n",
            "Training acc: 0.9936825037002563\n",
            "Training acc: 0.9964220523834229\n",
            "Training acc: 0.9913039207458496\n",
            "Training acc: 0.9971636533737183\n",
            "Training acc: 0.9977700710296631\n",
            "Training acc: 0.997801661491394\n",
            "Training acc: 0.9978244304656982\n",
            "Training acc: 0.9967949390411377\n",
            "Training acc: 0.9960766434669495\n",
            "Training acc: 0.9965810179710388\n",
            "Training acc: 0.9978829622268677\n",
            "Training acc: 0.9977824687957764\n",
            "Training acc: 0.998058021068573\n",
            "Training acc: 0.9980952739715576\n",
            "Training acc: 0.9964898824691772\n",
            "Training acc: 0.9980750679969788\n",
            "Training acc: 0.9982179999351501\n",
            "Training acc: 0.9965986609458923\n",
            "Training acc: 0.9982542991638184\n",
            "Training acc: 0.997961699962616\n",
            "Training acc: 0.9978135824203491\n",
            "Training acc: 0.99494868516922\n",
            "Training acc: 0.9980150461196899\n",
            "Training acc: 0.9982853531837463\n",
            "Training acc: 0.9979430437088013\n",
            "Training acc: 0.9984044432640076\n",
            "Training acc: 0.9975706934928894\n",
            "Training acc: 0.9982491135597229\n",
            "Training acc: 0.9983164072036743\n",
            "Training acc: 0.9981051087379456\n",
            "Training acc: 0.9982827305793762\n",
            "Training acc: 0.9983184933662415\n",
            "Training acc: 0.9984381198883057\n",
            "Training acc: 0.9980626702308655\n",
            "Training acc: 0.9963407516479492\n",
            "Training acc: 0.9960077404975891\n",
            "Training acc: 0.9891842603683472\n",
            "Training acc: 0.9965075254440308\n",
            "Training acc: 0.9954800605773926\n",
            "Training acc: 0.996648371219635\n",
            "Training acc: 0.9967037439346313\n",
            "Training acc: 0.9976535439491272\n",
            "Training acc: 0.9973697662353516\n",
            "Training acc: 0.9975618720054626\n",
            "Training acc: 0.998216986656189\n",
            "Training acc: 0.9969440698623657\n",
            "Training acc: 0.9981092810630798\n",
            "Training acc: 0.9982495903968811\n",
            "Training acc: 0.9983267784118652\n",
            "Training acc: 0.9978228807449341\n",
            "Training acc: 0.9983252286911011\n",
            "Training acc: 0.9982884526252747\n",
            "Training acc: 0.9982014298439026\n",
            "Training acc: 0.9983692169189453\n",
            "Training acc: 0.9982666969299316\n",
            "Training acc: 0.9982568621635437\n",
            "Training acc: 0.9984334707260132\n",
            "Training acc: 0.9984298348426819\n",
            "Training acc: 0.9984717965126038\n",
            "Training acc: 0.9984878301620483\n",
            "Training acc: 0.9955085515975952\n",
            "Training acc: 0.9982884526252747\n",
            "Training acc: 0.9984510540962219\n",
            "Training acc: 0.9985074996948242\n",
            "Training acc: 0.9985841512680054\n",
            "Training acc: 0.9983516335487366\n",
            "Training acc: 0.9986183643341064\n",
            "Training acc: 0.9984826445579529\n",
            "Training acc: 0.9982247352600098\n",
            "Training acc: 0.9985209703445435\n",
            "Training acc: 0.995185375213623\n",
            "Training acc: 0.9984148144721985\n",
            "Training acc: 0.9983920454978943\n",
            "Training acc: 0.9977721571922302\n",
            "Training acc: 0.9986199140548706\n",
            "Training acc: 0.9986592531204224\n",
            "Training acc: 0.9956411123275757\n",
            "Training acc: 0.9985795021057129\n",
            "Training acc: 0.9987441897392273\n",
            "Training acc: 0.9987006783485413\n",
            "Training acc: 0.9986178278923035\n",
            "Training acc: 0.9986478686332703\n",
            "Training acc: 0.9985411763191223\n",
            "Training acc: 0.9984365701675415\n",
            "Training acc: 0.9984013438224792\n",
            "Training acc: 0.9984267354011536\n",
            "Training acc: 0.9984210133552551\n",
            "Training acc: 0.998622477054596\n",
            "Training acc: 0.9984355568885803\n",
            "Training acc: 0.9983034729957581\n",
            "Training acc: 0.9982760548591614\n",
            "Training acc: 0.9984515905380249\n",
            "Training acc: 0.9984090924263\n",
            "Training acc: 0.9983702898025513\n",
            "Training acc: 0.9983537197113037\n",
            "Training acc: 0.9985862374305725\n",
            "Training acc: 0.9974526166915894\n",
            "Training acc: 0.9985328912734985\n",
            "Training acc: 0.9985334277153015\n",
            "Training acc: 0.9984774589538574\n",
            "Training acc: 0.9982537627220154\n",
            "Training acc: 0.9985939860343933\n",
            "Training acc: 0.9985370635986328\n",
            "Training acc: 0.9976406097412109\n",
            "Training acc: 0.9975696802139282\n",
            "Training acc: 0.9985764026641846\n",
            "Training acc: 0.9986100792884827\n",
            "Training acc: 0.9985489249229431\n",
            "Training acc: 0.9985484480857849\n",
            "Training acc: 0.9985629320144653\n",
            "Training acc: 0.9972723722457886\n",
            "Training acc: 0.9985038638114929\n",
            "Training acc: 0.9986074566841125\n",
            "Training acc: 0.9976597428321838\n",
            "Training acc: 0.9986985921859741\n",
            "Training acc: 0.9985774159431458\n",
            "Training acc: 0.9987032413482666\n"
          ]
        }
      ],
      "source": [
        "node_features = G.ndata['h']\n",
        "edge_features = G.edata['h']\n",
        "\n",
        "edge_label = G.edata['label']\n",
        "train_mask = G.edata['train_mask']\n",
        "\n",
        "model = Model(G.ndata['h'].shape[2], 128, G.ndata['h'].shape[2], F.relu, 0.2).cuda()\n",
        "opt = th.optim.Adam(model.parameters())\n",
        "\n",
        "for epoch in range(1,20000):\n",
        "    pred = model(G, node_features,edge_features).cuda()\n",
        "    loss = criterion(pred[train_mask] ,edge_label[train_mask])\n",
        "    opt.zero_grad()\n",
        "    loss.backward()\n",
        "    opt.step()\n",
        "    if epoch % 100 == 0:\n",
        "      print('Training acc:', compute_accuracy(pred[train_mask], edge_label[train_mask]))\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 39,
      "metadata": {
        "id": "p7gYo6lVtHCN"
      },
      "outputs": [],
      "source": [
        "X_test = encoder.transform(X_test)"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 40,
      "metadata": {
        "id": "OUGIEbMFtSnf"
      },
      "outputs": [],
      "source": [
        "X_test[cols_to_norm] = scaler.transform(X_test[cols_to_norm])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 41,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 416
        },
        "id": "VlyqlEqjtb9s",
        "outputId": "963f45bd-b4e0-4412-d884-1a6a8d6daaf7"
      },
      "outputs": [
        {
          "data": {
            "text/html": [
              "<div>\n",
              "<style scoped>\n",
              "    .dataframe tbody tr th:only-of-type {\n",
              "        vertical-align: middle;\n",
              "    }\n",
              "\n",
              "    .dataframe tbody tr th {\n",
              "        vertical-align: top;\n",
              "    }\n",
              "\n",
              "    .dataframe thead th {\n",
              "        text-align: right;\n",
              "    }\n",
              "</style>\n",
              "<table border=\"1\" class=\"dataframe\">\n",
              "  <thead>\n",
              "    <tr style=\"text-align: right;\">\n",
              "      <th></th>\n",
              "      <th>IPV4_SRC_ADDR</th>\n",
              "      <th>IPV4_DST_ADDR</th>\n",
              "      <th>PROTOCOL</th>\n",
              "      <th>L7_PROTO</th>\n",
              "      <th>IN_BYTES</th>\n",
              "      <th>OUT_BYTES</th>\n",
              "      <th>IN_PKTS</th>\n",
              "      <th>OUT_PKTS</th>\n",
              "      <th>TCP_FLAGS</th>\n",
              "      <th>FLOW_DURATION_MILLISECONDS</th>\n",
              "      <th>label</th>\n",
              "    </tr>\n",
              "  </thead>\n",
              "  <tbody>\n",
              "    <tr>\n",
              "      <th>1212302</th>\n",
              "      <td>172.23.149.141:59622</td>\n",
              "      <td>192.168.1.184:443</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>-0.650380</td>\n",
              "      <td>-0.007747</td>\n",
              "      <td>-0.025740</td>\n",
              "      <td>-0.005635</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>-0.055286</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>319684</th>\n",
              "      <td>172.23.37.68:38636</td>\n",
              "      <td>52.59.177.21:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.745102</td>\n",
              "      <td>-0.005689</td>\n",
              "      <td>0.096934</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>0.002229</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.042802</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>161128</th>\n",
              "      <td>172.28.125.52:50748</td>\n",
              "      <td>192.168.1.152:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005531</td>\n",
              "      <td>0.009846</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.004218</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.054768</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>809034</th>\n",
              "      <td>172.22.89.90:59096</td>\n",
              "      <td>91.189.91.139:53</td>\n",
              "      <td>-2.765838</td>\n",
              "      <td>-3.838612</td>\n",
              "      <td>-0.007960</td>\n",
              "      <td>-0.025028</td>\n",
              "      <td>-0.005957</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>-1.149118</td>\n",
              "      <td>-0.052886</td>\n",
              "      <td>0</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1003939</th>\n",
              "      <td>172.26.73.154:46164</td>\n",
              "      <td>192.168.1.190:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.007747</td>\n",
              "      <td>-0.025740</td>\n",
              "      <td>-0.005635</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>-0.055286</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>...</th>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "      <td>...</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>569840</th>\n",
              "      <td>172.20.147.103:59240</td>\n",
              "      <td>192.168.1.152:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005138</td>\n",
              "      <td>0.009846</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.004218</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.053689</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>590187</th>\n",
              "      <td>172.25.2.74:42914</td>\n",
              "      <td>192.168.1.190:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005623</td>\n",
              "      <td>-0.004783</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.004218</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.051916</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1112800</th>\n",
              "      <td>172.21.235.155:58262</td>\n",
              "      <td>192.168.1.184:443</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>-0.650380</td>\n",
              "      <td>-0.007747</td>\n",
              "      <td>-0.025740</td>\n",
              "      <td>-0.005635</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>-0.055286</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>174527</th>\n",
              "      <td>172.25.250.120:36724</td>\n",
              "      <td>192.168.1.195:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.005863</td>\n",
              "      <td>-0.005514</td>\n",
              "      <td>-0.004667</td>\n",
              "      <td>-0.005293</td>\n",
              "      <td>0.485718</td>\n",
              "      <td>-0.053121</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "    <tr>\n",
              "      <th>1250859</th>\n",
              "      <td>172.27.56.188:59052</td>\n",
              "      <td>192.168.1.152:80</td>\n",
              "      <td>0.305473</td>\n",
              "      <td>0.583457</td>\n",
              "      <td>-0.007747</td>\n",
              "      <td>-0.025740</td>\n",
              "      <td>-0.005635</td>\n",
              "      <td>-0.009591</td>\n",
              "      <td>0.466183</td>\n",
              "      <td>-0.055286</td>\n",
              "      <td>1</td>\n",
              "    </tr>\n",
              "  </tbody>\n",
              "</table>\n",
              "<p>413783 rows × 11 columns</p>\n",
              "</div>"
            ],
            "text/plain": [
              "                IPV4_SRC_ADDR  ... label\n",
              "1212302  172.23.149.141:59622  ...     1\n",
              "319684     172.23.37.68:38636  ...     1\n",
              "161128    172.28.125.52:50748  ...     1\n",
              "809034     172.22.89.90:59096  ...     0\n",
              "1003939   172.26.73.154:46164  ...     1\n",
              "...                       ...  ...   ...\n",
              "569840   172.20.147.103:59240  ...     1\n",
              "590187      172.25.2.74:42914  ...     1\n",
              "1112800  172.21.235.155:58262  ...     1\n",
              "174527   172.25.250.120:36724  ...     1\n",
              "1250859   172.27.56.188:59052  ...     1\n",
              "\n",
              "[413783 rows x 11 columns]"
            ]
          },
          "execution_count": 41,
          "metadata": {
            "tags": []
          },
          "output_type": "execute_result"
        }
      ],
      "source": [
        "X_test"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 42,
      "metadata": {
        "id": "q5CMxVe5xIDb"
      },
      "outputs": [],
      "source": [
        "X_test['h'] = X_test[ cols_to_norm ].values.tolist()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 91,
      "metadata": {
        "id": "VsAmtLAbxN_6"
      },
      "outputs": [],
      "source": [
        "G_test = nx.from_pandas_edgelist(X_test, \"IPV4_SRC_ADDR\", \"IPV4_DST_ADDR\", ['h','label'],create_using=nx.MultiGraph())\n",
        "G_test = G_test.to_directed()\n",
        "G_test = from_networkx(G_test,edge_attrs=['h','label'] )\n",
        "actual = G_test.edata.pop('label')\n",
        "G_test.ndata['feature'] = th.ones(G_test.num_nodes(), G.ndata['h'].shape[2])"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 92,
      "metadata": {
        "id": "Eeux6JIxxQtC"
      },
      "outputs": [],
      "source": [
        "G_test.ndata['feature'] = th.reshape(G_test.ndata['feature'], (G_test.ndata['feature'].shape[0], 1, G_test.ndata['feature'].shape[1]))"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 93,
      "metadata": {
        "id": "PBETQI3YxYay"
      },
      "outputs": [],
      "source": [
        "G_test.edata['h'] = th.reshape(G_test.edata['h'], (G_test.edata['h'].shape[0], 1, G_test.edata['h'].shape[1]))\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 94,
      "metadata": {
        "id": "qlTOyVN6xZZB"
      },
      "outputs": [],
      "source": [
        "G_test = G_test.to('cuda:0')\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 95,
      "metadata": {
        "id": "QyugNIt9xac6"
      },
      "outputs": [],
      "source": [
        "import timeit\n",
        "start_time = timeit.default_timer()\n",
        "node_features_test = G_test.ndata['feature']\n",
        "edge_features_test = G_test.edata['h']\n",
        "test_pred = model(G_test, node_features_test, edge_features_test).cuda()\n",
        "elapsed = timeit.default_timer() - start_time"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 96,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "KecCvilSxcFK",
        "outputId": "66c83550-1208-46a0-e65d-16dbad5a256e"
      },
      "outputs": [
        {
          "name": "stdout",
          "output_type": "stream",
          "text": [
            "0.05728961600107141 seconds\n"
          ]
        }
      ],
      "source": [
        "print(str(elapsed) + ' seconds')\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 97,
      "metadata": {
        "id": "BNQLnLoAxdST"
      },
      "outputs": [],
      "source": [
        "test_pred = test_pred.argmax(1)\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 98,
      "metadata": {
        "id": "9dtggXXsxevx"
      },
      "outputs": [],
      "source": [
        "test_pred = th.Tensor.cpu(test_pred).detach().numpy()\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 99,
      "metadata": {
        "id": "5TGb_KWRxfzS"
      },
      "outputs": [],
      "source": [
        "actual = [\"Normal\" if i == 0 else \"Attack\" for i in actual]\n",
        "test_pred = [\"Normal\" if i == 0 else \"Attack\" for i in test_pred]"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 100,
      "metadata": {
        "id": "n7z7tHTPxhBC"
      },
      "outputs": [],
      "source": [
        "from sklearn.metrics import plot_confusion_matrix\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 101,
      "metadata": {
        "id": "uMRairwzxiBC"
      },
      "outputs": [],
      "source": [
        "import numpy as np\n",
        "\n",
        "\n",
        "def plot_confusion_matrix(cm,\n",
        "                          target_names,\n",
        "                          title='Confusion matrix',\n",
        "                          cmap=None,\n",
        "                          normalize=True):\n",
        "    \n",
        "    import matplotlib.pyplot as plt\n",
        "    import numpy as np\n",
        "    import itertools\n",
        "\n",
        "    accuracy = np.trace(cm) / float(np.sum(cm))\n",
        "    misclass = 1 - accuracy\n",
        "\n",
        "    if cmap is None:\n",
        "        cmap = plt.get_cmap('Blues')\n",
        "\n",
        "    plt.figure(figsize=(12, 12))\n",
        "    plt.imshow(cm, interpolation='nearest', cmap=cmap)\n",
        "    plt.title(title)\n",
        "    plt.colorbar()\n",
        "\n",
        "    if target_names is not None:\n",
        "        tick_marks = np.arange(len(target_names))\n",
        "        plt.xticks(tick_marks, target_names, rotation=45)\n",
        "        plt.yticks(tick_marks, target_names)\n",
        "\n",
        "    if normalize:\n",
        "        cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
        "\n",
        "\n",
        "    thresh = cm.max() / 1.5 if normalize else cm.max() / 2\n",
        "    for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):\n",
        "        if normalize:\n",
        "            plt.text(j, i, \"{:0.4f}\".format(cm[i, j]),\n",
        "                     horizontalalignment=\"center\",\n",
        "                     color=\"white\" if cm[i, j] > thresh else \"black\")\n",
        "        else:\n",
        "            plt.text(j, i, \"{:,}\".format(cm[i, j]),\n",
        "                     horizontalalignment=\"center\",\n",
        "                     color=\"white\" if cm[i, j] > thresh else \"black\")\n",
        "\n",
        "\n",
        "    plt.tight_layout()\n",
        "    plt.ylabel('True label')\n",
        "    plt.xlabel('Predicted label\\naccuracy={:0.4f}; misclass={:0.4f}'.format(accuracy, misclass))\n",
        "    plt.show()"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 102,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 873
        },
        "id": "KNCkVWyqxjaR",
        "outputId": "596872d9-f8e2-4c95-f976-ecb58a88754e"
      },
      "outputs": [
        {
          "data": {
            "image/png": "iVBORw0KGgoAAAANSUhEUgAAA0UAAANYCAYAAAALz0bwAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjIsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy+WH4yJAAAgAElEQVR4nOzde9ivY5k//ve51rJEyF4SUinZRMimIpFdMnynJrQhKe2nmcm0mRqqqfnVtNdGU1OyqRFFFJG0l2STFGkoCZEsVJLF4vr98dz0WD3rWYvWcz+f1v16Hcd9PJ/7unfX5zNHOOc8r/Ou1loAAACGasZ0TwAAAGA6CYoAAIBBExQBAACDJigCAAAGTVAEAAAM2qzpngAAAPBnM1dYt7V5f5ruaSxU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jNVzw2WmSJIkSVKvGRRJkiRJ6jXL5yRJkqRxY/3cUJkpkiRJktRrBkWSJEmSes2gSJIkSVKvOadIkiRJGjNxUtFQmSmSJEmS1GsGRZIkSZJ6zfI5SZIkaYwEiNVzQ2WmSJIkSVKvGRRJkiRJ6rVU1ajHIEmSJKlJchqw3qjHMQNLq2rhqAcxGwyKJEmSJPWa5XOSJEmSes2gSJIkSVKvGRRJkiRJ6jWDIkmSJEm9ZlAkSZIkqdf+P2gvAxwus6g0AAAAAElFTkSuQmCC",
            "text/plain": [
              "<Figure size 864x864 with 2 Axes>"
            ]
          },
          "metadata": {
            "needs_background": "light",
            "tags": []
          },
          "output_type": "display_data"
        }
      ],
      "source": [
        "from sklearn.metrics import confusion_matrix\n",
        "\n",
        "plot_confusion_matrix(cm = confusion_matrix(actual, test_pred), \n",
        "                      normalize    = False,\n",
        "                      target_names = np.unique(actual),\n",
        "                      title        = \"Confusion Matrix\")"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "id": "vrmEBTGXM3hM"
      },
      "outputs": [],
      "source": []
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "collapsed_sections": [],
      "machine_shape": "hm",
      "name": "unsw_ton_iot_binary_mean_agg.ipynb",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.8.5"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}
